package com.ustadzmenjawab.twitter;

import java.util.Hashtable;
import java.util.List;

import twitter4j.ResponseList;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.User;
import twitter4j.UserList;
import twitter4j.conf.ConfigurationBuilder;

import com.ustadzmenjawab.conf.Configuration;
import com.ustadzmenjawab.db.DBAccess;
import com.ustadzmenjawab.util.TwitterUtil;

public class SearchSimilarUser {

	public static void main(String[] args) {
		ConfigurationBuilder cb = new ConfigurationBuilder();
		cb.setDebugEnabled(true)
		.setIncludeRTsEnabled(true)
		.setIncludeEntitiesEnabled(true)
		.setOAuthConsumerKey(Configuration.getProperty("REST_OAUTH_CONSUMER_KEY"))
		.setOAuthConsumerSecret(Configuration.getProperty("REST_OAUTH_CONSUMER_SECRET"))
		.setOAuthAccessToken(Configuration.getProperty("REST_OAUTH_ACCESS_TOKEN"))
		.setOAuthAccessTokenSecret(Configuration.getProperty("REST_OAUTH_ACCESS_TOKEN_SECRET"));
		twitter4j.conf.Configuration twconf = cb.build();
		Twitter restAPI = new TwitterFactory(twconf).getInstance();
		
		DBAccess db = new DBAccess();
		Hashtable<Long,String> listIDs = db.getUstadzList();
		for(Long id : listIDs.keySet()){
			try{
				String scrName = listIDs.get(id);
				TwitterUtil.checkHitLimit(restAPI);
				 ResponseList<User> ul = restAPI.searchUsers(scrName, 5);
				 System.out.println("get similar users to : " + scrName);
				 for(User u : ul){
					 
					 db.insertSimilarUser(u);
				 }
				
			}catch(Exception e){
				e.printStackTrace();
			}
		}

	}

}
